﻿using System;
using System.Web;

namespace Kratos.Framework.Function
{
    /// <summary>
    /// 基础缓存操作类
    /// </summary>
    public static class KratosCache
    {
        public static void Set(string key, object value)
        {
            var cache = HttpRuntime.Cache;
            cache[key] = value;
        }

        public static void Set(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            var cache = HttpRuntime.Cache;
            cache.Insert(key, value, null, absoluteExpiration, slidingExpiration);
        }

        public static T Get<T>(string key) where T : class
        {
            var val = Get(key);
            if ((val as T) != null)
                return val as T;

            return null;
        }

        public static object Get(string key)
        {
            var cache = HttpRuntime.Cache;
            return cache[key];
        }
    }
}
